//    Copyright (C) Kherty.  All rights reserved.
namespace OpenLS.Spreadsheet
{
    public class EndsWithFormattingRule : StandardConditionalFormattingRule
    {
        internal override ConditionalFormattingType Type
        {
            get { return ConditionalFormattingType.EndsWith; }
        }
        internal override void PrepareBeforeWrite(ConditionalFormatting conditionalFormatting, FormatType formatType)
        {
            var cell = conditionalFormatting.Range.TopLeftCell;
            this.Formula1 = string.Format("=RIGHT({0}, {1})=\"{2}\"", cell.Label, this.Text.Length, EscapedText);
        }
        internal override bool Apply(Cell cell)
        {
            string s = cell.Value as string;
            bool b = s != null && s.EndsWith(Text);
            return ApplyStyle(cell, b);
        }
    }
}
